package com.ego.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ego.admin.dao.SysNoticeDao;
import com.ego.admin.po.SysNotice;
import com.ego.admin.service.SysNoticeService;
import com.ego.admin.vo.SysNoticeSearchVo;
import com.ego.common.util.PageUtil;
import com.ego.common.vo.PageVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @program: ego
 * @description:
 * @author: KamTang
 * @create: 2022-11-16 20:02
 **/
@Service("sysNoticeService")
public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeDao, SysNotice> implements SysNoticeService {
    @Override
    public PageVo<SysNotice> search(SysNoticeSearchVo search) {
        LambdaQueryWrapper<SysNotice> query = Wrappers.<SysNotice>lambdaQuery()
                .eq(search.getStatus() != null, SysNotice::getStatus, search.getStatus())
                .eq(search.getType() != null, SysNotice::getType, search.getType());
        if (StringUtils.isNotEmpty(search.getKeyword())) {
            query.and(q -> q.like(SysNotice::getTitle, search.getNoticeTitle())
                    .or().like(SysNotice::getCreateBy, search.getCreateBy()));
        }
        Page<SysNotice> page = baseMapper.selectPage(Page.of(search.getPageNum(), search.getPageSize()), query);
        return PageUtil.toPage(page);
    }
}
